package com.tefl.common.util;

import java.sql.SQLException;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.tefl.entity.Dept;
import com.tefl.entity.InfGrade;
import com.tefl.entity.InfStatus;
import com.tefl.entity.SysMenu;

/**
 * 数据库常用类 序列操作、常用数据加载
 * 
 * @author liuxin
 * 
 */
public class DataBaseHelper {

	private static SqlMapClient client;
	
	static{
		ApplicationContext c = new ClassPathXmlApplicationContext("beans.xml");
		client = (SqlMapClient) c.getBean("client");
	}

	/**
	 * 获取指定序列的下一个值
	 * 
	 * @param sequenceName
	 *            序列名称
	 * @return 序列值
	 * @throws SQLException
	 */
	public static String getNextSequence(String sequenceName)
			throws SQLException {
		return (String) DataBaseHelper.client.queryForObject("getNextSequence",
				sequenceName);
	}

	/**
	 * 查询所有等级信息
	 * 
	 * @return 等级集合
	 * @throws SQLException
	 */
	public static List<InfGrade> getAllGrade() throws SQLException {
		return DataBaseHelper.client.queryForList("getAllGrade");
	}

	/**
	 * 查询所有状态信息
	 * 
	 * @return 状态集合
	 * @throws SQLException
	 */
	public static List<InfStatus> getAllStatus() throws SQLException {
		return DataBaseHelper.client.queryForList("getAllStatus");
	}

	/**
	 * 查询所有学院信息
	 * 
	 * @return 学院集合
	 * @throws SQLException
	 */
	public static List<Dept> getAllDept() throws SQLException {
		return DataBaseHelper.client.queryForList("getAllDept");
	}

	/**
	 * 查询所有菜单信息
	 * 
	 * @return 菜单集合
	 * @throws SQLException
	 */
	public static List<SysMenu> getAllMenu() throws SQLException {
		return DataBaseHelper.client.queryForList("getAllMenu");
	}
}
